package com.dixon.worddayday.util;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author dixon
 * @version 1.0.0
 * @Description TODO
 * @createTime 2023年04月29日 13:48:00
 */
public class AudioDownloader {
    public static void main(String[] args) throws Exception {
        String audioUrl = "https://example.com/audio.mp3";
        String savePath = "/path/to/save/file/audio.mp3";

        URL url = new URL(audioUrl);
        URLConnection connection = url.openConnection();
        BufferedInputStream inputStream = new BufferedInputStream(connection.getInputStream());
        FileOutputStream outputStream = new FileOutputStream(savePath);

        byte[] buffer = new byte[1024];
        int count = 0;
        while ((count = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, count);
        }

        outputStream.flush();
        outputStream.close();
        inputStream.close();

        System.out.println("Audio file downloaded successfully.");
    }
}